﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NHibernate;
using DotNet.Common.NHibernateUtil;
using ZLCMS.Data.Model;
using DotNet.Common.Command;
using ZLCMS.Business.Commands.SessionCommands;

namespace ZLCMS.Web.MemberUser
{
        public partial class GenerateAccount : System.Web.UI.Page
        {
                protected void Page_Load(object sender, EventArgs e)
                {
                        using (ISession session = SessionFactoryHelper.CreateSession())
                        {
                                MemberInfo memberDb = new MemberInfo();
                                memberDb.AccountId = Guid.NewGuid().ToString("N");
                                memberDb.Remarks = "";
                                memberDb.AddDate = DateTime.Now;
                                memberDb.Birthday = DateTime.Now;
                                memberDb.LastLog = DateTime.Now;
                                memberDb.LogTimes = 1;
                                memberDb.PhotoUrl = "";
                                memberDb.Introduction = "";
                                memberDb.AdvancePayment = 0;
                                memberDb.Score = 0;
                                memberDb.Coins = 0;
                                memberDb.Status = "1";
                                memberDb.Introducer = "1";
                                memberDb.Level = "1";
                                memberDb.OwnerAccount = "admin";
                                if (Request["type"] == "weibo")
                                {
                                        memberDb.SinaOpenId = Request["openid"];
                                }
                                else
                                {
                                        memberDb.QqOpenId = Request["openid"];
                                }
                                session.Save(memberDb);
                                session.Flush();
                                //登录
                                ICommandResult<LoginResult> res = new LoginCommand().Execute(new LoginParameter() { Telephone = Request["OpenId"], LoginType = Request["type"] });
                                if (!res.Error)
                                {
                                        Response.Redirect("/MemberUser/default.aspx");
                                }
                        }

                }
        }
}